<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	 "http://www.w3.org/TR/html4/transitional.dtd">
<html>
<head>
<title>lsyslog: a Lua wrapper for the syslog C API</title>
</head>
<body>

<h3>What is it</h3>
lsyslog is a Lua module that wraps the 
<a href="http://www.die.net/doc/linux/man/man3/syslog.3.html">syslog(3)</a> C API. 
It has been tested with Lua 5.1 on Linux.

<h3>Download</h3>
The latest version can be found at 
<a href="http://luaforge.net/frs/?group_id=262">LuaForge</a>.

<h3>Compiling</h3>
To compile the module, just edit the <code>Makefile</code> to reflect your 
installation of Lua. Then run make. This will build the library and run a simple test.

<h3>Installing</h3>
To intall the module, just copy 
<code>syslog.so</code> somewhere in your 
<a href="http://www.lua.org/pil/8.1.html">
<code>LUA_CPATH</code></a>.


<h3>Usage</h3>
The library exports the following Lua functions:

<ul>
<li><code>openlog(ident, option[, facility]) </code>
<li><code>syslog(priority, message) </code>
<li><code>closelog() </code>
</ul>

<p>See <code>test.lua</code>, which shows the library in action.
</p>

<p>You may want to wrap the standard <code>assert</code> and
<code>error</code> Lua calls so that they log the assertion or error before
aborting the program. This can be useful for post-mortem analysis of 
embedded or unattended Lua applications. You can append this code at the end of 
<code>strict.lua</code>, a module that can be found in the 
<code>etc</code> directory of the Lua sources, and which is worth including
anyway.
</p>

<pre>
if pcall(require, "syslog") then -- only if syslog lib is avalible

	-- set the ident string to the lua filename that first included this module
	--local func_info = debug.getinfo(3, "S")
	--if func_info then
	--	syslog.openlog(func_info.short_src, syslog.LOG_ODELAY, "LOG_USER")
	--end

	-- make error call syslog.syslog too
	local _error = error
	_G.error = function(txt, level)
		if level then
			level = level + 1
		else
			level = 2
		end
		local info = debug.getinfo(level, "Sl")
		local msg
		if info.what == "C" then
			msg = "[C function] "
		else
			msg = string.format("[%s]:%d ", info.short_src, info.currentline)
		end
		syslog.syslog("LOG_ERR", msg .. (txt or ""))
		_error(txt, level)
	end

	-- make assert call our modified error function
	_G.assert = function (...)
		local cond, txt = ...
		if not cond then
			error(txt or "assertion failed!", 2)
		end
		return ...
	end

end
</pre>

Then call <code>require "strict"</code> at the top of your code.

<h3>License</h3>
This code is hereby placed in the public domain.
Please send comments, suggestions, and bug reports to
<a href="mailto:jesus.ruizdeinfante@hale.at">jesus.ruizdeinfante@hale.at</a> .



<h3>Thanks</h3>
Thanks to <a href="http://www.tecgraf.puc-rio.br/~lhf>
Luiz Henrique de Figueiredo</a> for the Makefile.

</body>
</html>

